package com.epam.cdp.selenium2.core.runner;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.openqa.selenium.WebDriver;

import com.epam.cdp.selenium2.core.common.webdriver.WebDriverType;
import com.epam.cdp.selenium2.core.results.logger.Logger;

/**
 * Main class to run test cases
 * 
 * @author avarabyeu
 * 
 */
public class Runner extends TestRunner
{

  public static WebDriver Driver;

  /*
   * 
   * To use driver in tests use WebDriver Driver = Browser.getInstance().getWebdriver();
   */

  public static void main( String[] args ) throws CmdLineException
  {
    initRunnerInstance( args );
    CLIparser cli = new CLIparser();
    CmdLineParser parser = new CmdLineParser( cli );
    try
    {
      parser.parseArgument( args );
    }
    catch( CmdLineException e )
    {
      e.printStackTrace();
    }
    Browser.getInstance().setDriverHost( cli.hostname );
    Browser.getInstance().setDriverType( WebDriverType.getByDriverName( cli.driverType ) );
    Browser.getInstance().getWebdriver();

    runTests();
  }

  private static Runner tr = null;

  private static void initRunnerInstance( String args[] ) throws CmdLineException
  {
    tr = new Runner( args );
  }

  private static void runTests()
  {
    try
    {
      tr.run();
    }
    finally
    {
      Logger.shutdown();
    }
  }

  public Runner( String[] args ) throws CmdLineException
  {
    super( args );
  }

}
